/**
 * 热门活动
 * @author Qasim <15750783791@163.com>
 * @version 2016/9/5
 */
var self = home_info = '';

document.addEventListener('plusready' , ready ,  false);

function ready(){
	
	self = plus.webview.currentWebview();
	
	//获取缓存的数据
	home_info = plus.storage.getItem('home_info');
	
	if(home_info){//如果有 直接显示
		
		showInfo();
		
	}else{
		
		toast('没有获取到数据 ,请刷新首页获取最新数据');
	}
	
	//搜索
 	$('.search').on('click' , function(){
 		search(4); 
 	})
}


//数据显示在页面
function showInfo(){
	
	plus.nativeUI.showWaiting('加载中...'); 
	
	setTimeout(function(){ 
		plus.nativeUI.closeWaiting();
	} , 1000);
	
	home_info = $.parseJSON(home_info);
	
	
	//热门活动
	if(home_info.hot_activity){
		
		$.each(home_info.hot_activity , function(k ,v){
			var list  = '<div class="position-re margin-bottom-5" data-id="'+v.id+'" data-tid="'+v.tid+'" data-phone="'+v.phone+'" data-title="'+v.title+'" ><img src="'+getImgUrl(v.litpic)+'"/>';
				list += '<div class="span-bar color-white font-14">';
				list += '<span class="mui-pull-left mui-col-xs-9">'+v.title+'</span>';
				list += '<span class="mui-pull-left mui-col-xs-3 mui-text-right">'+v.addtime+'</span><div class="avtivity_content" style="display:none">'+v.body+'</div></div></div>';
			$('.lists').append(list); 
			
		})
		//前往活动详情页面
		$('.position-re').unbind();
		$('.position-re').on('click' , function(){
			plus.nativeUI.showWaiting('跳转中...');
			var hd_inf = plus.webview.create('hd-inf.html' , 'hd-inf' , {} , {
				tid : $(this).attr('data-tid') ,
				phone : $(this).attr('data-phone'), 
				title : $(this).attr('data-title') ,
				body : $(this).find('.avtivity_content').html() ,
				aid : $(this).attr('data-id')
			});
			hd_inf.addEventListener('loaded' , function(){
				hd_inf.show('slide-in-right');
				plus.nativeUI.closeWaiting();
			})

		})
		
	}
	 
}

